package com.oa.dao.impl;

import com.oa.dao.BaseDao;
import com.oa.dao.DepartmentDao;
import com.oa.entity.Attendance;
import com.oa.entity.Department;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2022/7/5 9:19
 **/
public class DepartmentDaoImpl extends BaseDao implements DepartmentDao {
	@Override
	public List<Department> findAll() {
		//2、创建连接对象
		Connection conn = getConnection();
		//3、编写sql
		String sql = "select * from Attendance where 1=1 ";
		//4、创建执行对象
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			pstm = conn.prepareStatement(sql);
			//5、执行
			rs = pstm.executeQuery(); //虚拟表==》查询结果的表
			//6、处理执行结果
			List<Department> list = new ArrayList<Department>();
			while(rs.next()){
				Department tmp = new Department(rs.getInt("id"),rs.getString("deptName"));
				list.add(tmp);
			}
			return list;
		} catch (SQLException throwables) {
			throwables.printStackTrace();
		}finally {
			//7、关闭
			closeAll(rs,pstm,conn);
		}
		return null;
	}
}
